package main

import (
	"fmt"
	"net/http"

	"read.com/wxmp/api"
	"read.com/wxmp/dao"
	"read.com/wxmp/handler"
	"read.com/wxmp/service"
)

func main() {
	if err := dao.InitDb(); err != nil {
		fmt.Println("init database error.", err)
		return
	}
	if err := dao.LoadTable(); err != nil {
		fmt.Println("load table error.", err)
		return
	}
	defer dao.CloseDb()

	// 初始化微信Token
	api.InitAccessToken()

	// 获取所有公众号信息
	appList := dao.GetAppList()
	for _, app := range appList {
		// 自定义菜单
		service.CreateWxMenu(app)
	}

	h := handler.Register()
	http.ListenAndServe("127.0.0.1:9000", h)
	fmt.Println("dfdsfsdfsdfsdfsdfsd")
}
